﻿using IPMS.DAL;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;

public class TreeViewData
{
    public static ProductList GetProductsForProjectGroup(string projectGroupID)
    {
        ProductList products = new ProductList();
        SqlDataSource mySource = new SqlDataSource(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString, "IP_GetProductsForProjectGroupSp");
        mySource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
        mySource.SelectParameters.Add(new Parameter("ProjectGroupID", TypeCode.String, projectGroupID));
        IEnumerable result = mySource.Select(DataSourceSelectArguments.Empty);
        try
        {
            foreach (DataRowView row in result)
            {
                products.Add(new Products(row["Model"].ToString()));
            }
        }
        catch (Exception)
        {
        }
        return products;
    }

    public int GetProjectGroupByPGIForPatentPCTDate(string ProjectGroupID, out string PCT)
    {
        SqlCommand sqlCmd = new SqlCommand();
        DataAccessLayer DAL = new DataAccessLayer();
        DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
        DAL.AddParamToSQLCmd(sqlCmd, "@ProjectGroupID", SqlDbType.NVarChar, 30, ParameterDirection.Input, ProjectGroupID);
        DAL.AddParamToSQLCmd(sqlCmd, "@PCT", SqlDbType.NVarChar, 100, ParameterDirection.Output, null);
        DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "IP_GetProjectGroupByPGIForPatentPCTDateSp");
        DAL.ExecuteScalarCmd(sqlCmd);
        PCT = Convert.ToString(sqlCmd.Parameters["@PCT"].Value);
        return Convert.ToInt16(sqlCmd.Parameters["@ReturnValue"].Value);
    }

    public static ProjectGroupList GetProjectGroups(string ProjectGroupID, string Culture)
    {
        ProjectGroupList projectgroups = new ProjectGroupList();
        SqlDataSource mySource = new SqlDataSource(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString, "IP_GetProjectGroupByPGISp");
        mySource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
        mySource.SelectParameters.Add(new Parameter("ProjectGroupID", TypeCode.String, ProjectGroupID));
        mySource.SelectParameters.Add(new Parameter("LocalID", TypeCode.String, Culture));
        IEnumerable result = mySource.Select(DataSourceSelectArguments.Empty);
        foreach (DataRowView row in result)
        {
            projectgroups.Add(new ProjectGroup(row["ProjectGroupID"].ToString(), row["PGI"].ToString()));
        }
        return projectgroups;
    }

    public static ProjectList GetProjectsForProjectGroup(string projectCode, string projectType, string OwnerGroupID, bool SuperUser, string UserName)
    {
        ProjectList projects = new ProjectList();
        SqlDataSource mySource = new SqlDataSource(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString, "IP_GetProjectForProjectGroupSp");
        mySource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
        mySource.SelectParameters.Add(new Parameter("ProjectGroupID", TypeCode.String, projectCode));
        mySource.SelectParameters.Add(new Parameter("ProjectType", TypeCode.String, projectType));
        mySource.SelectParameters.Add(new Parameter("OwnerGroupID", TypeCode.String, OwnerGroupID));
        mySource.SelectParameters.Add(new Parameter("SuperUser", TypeCode.Boolean, SuperUser.ToString()));
        mySource.SelectParameters.Add(new Parameter("UserName", TypeCode.String, UserName));
        IEnumerable result = mySource.Select(DataSourceSelectArguments.Empty);
        try
        {
            foreach (DataRowView row in result)
            {
                projects.Add(new Projects(row["ProjectCode"].ToString(), row["Type"].ToString()));
            }
        }
        catch (Exception)
        {
        }
        return projects;
    }
}

